#ifndef I2COP_H
#define I2COP_H


/* I2C Register */
#define I2C_Control                     0x0
#define I2C_Status                      0x4
#define I2C_ClockDiv                    0x8
#define I2C_Data                        0x0C
#define I2C_SlaveAddr                   0x10
#define I2C_TGSR                        0x14  /* 2003/05/28 Correct by Peter */
#define I2C_BMR                         0x18  /* 2003/05/28 Correct by Peter */

/* I2C Control register */


#define I2C_ALIEN                   0x2000  /* Arbitration lose */
#define I2C_SAMIEN                  0x1000  /* slave address match */
#define I2C_STOPIEN                 0x800   /* stop condition */
#define I2C_BERRIEN                 0x400   /* non ACK response */
#define I2C_DRIEN                   0x200   /* data receive */
#define I2C_DTIEN                   0x100   /* data transmit */
#define I2C_TBEN                    0x80    /* transfer byte enable */
#define I2C_ACKNAK                  0x40    /* ack sent */
#define I2C_STOP                    0x20    /* stop */
#define I2C_START                   0x10    /* start */
#define I2C_GCEN                    0x8     /* general call */
#define I2C_SCLEN                   0x4     /* enable clock */
#define I2C_I2CEN                   0x2     /* enable I2C */
#define I2C_I2CRST                  0x1     /* reset I2C */
#define I2C_ENABLE                  (I2C_ALIEN|I2C_SAMIEN|I2C_STOPIEN|I2C_BERRIEN|I2C_DRIEN|I2C_DTIEN|I2C_SCLEN|I2C_I2CEN)


/* I2C Status Register */

#define I2C_CLRAL                   0x400
#define I2C_CLRGC                   0x200
#define I2C_CLRSAM                  0x100
#define I2C_CLRSTOP                 0x80
#define I2C_CLRBERR                 0x40
#define I2C_DR                      0x20
#define I2C_DT                      0x10
#define I2C_BB                      0x8
#define I2C_BUSY                    0x4
#define I2C_ACK                     0x2
#define I2C_RW                      0x1


/* I2C clock divided register */

#define I2C_CLKCOUNT                0x3ff


/* I2C slave address register */

#define I2C_EN10                    0x80000000  /* 10-bit address slave mode */
#define I2C_SARMSB                  0x380       /* mask for SAR msb when EN10=1 */
#define I2C_SARLSB                  0x7f	    /* mask for SAR lsb */

/* Bus Monitor Register */

#define I2C_SCL                     0x2
#define I2C_SDA                     0x1



int I2C_Init(void);
//int I2C_RandomRead(unsigned char *buf, unsigned long address, unsigned long index, unsigned long num);
int I2C_Read(unsigned int address, unsigned int index);
//int I2C_PageWrite(unsigned char *buf, unsigned long address, unsigned long index, unsigned long num);
int I2C_Write (unsigned int address, unsigned int index, unsigned char value);
int I2C_saa7137_Write(unsigned char *buf, unsigned int num);
void fLib_I2C_SetClockdiv(unsigned int count);

#endif // I2COP_H
